package de.tabuma.pm.shopping;

import de.tabuma.shopping.controller.*;
import de.tabuma.shopping.entity.*;
import java.util.*;
import java.util.logging.*;
import de.tabuma.pm.constants;

/**
 * Facade for Shopping
 * @author$
 * @version$
 * @since$
 * @see de.tabuma.shopping.logik.LicensePackageFacade
 */
public class ShoppingFacade implements de.tabuma.shopping.logik.LicensePackageFacade {
    public static double getPrice(int licenseCount, double licensePrice, double asset) {
        double price = (licenseCount*licensePrice*(1+asset));
        price += 0.35;
        double newprice = price;
        for(int i=0;i<10;i++) {
            newprice = newprice * 0.039 + newprice * de.tabuma.shopping.constants.vat/100;
            price += newprice;
        }

        return price;
    }

    private License license11 = new License(1, 100, constants.PM_SHOPPING_VIEW_PUBLIC_LICENSE, 0);
    private License license12 = new License(2, 1000, constants.PM_SHOPPING_VIEW_PUBLIC_LICENSE, 0);
    private License license13 = new License(3, 5000, constants.PM_SHOPPING_VIEW_PUBLIC_LICENSE, 0);

    private License license21 = new License(4, 100, constants.PM_SHOPPING_VIEW_PROTECTED_LICENSE, 0);
    private License license22 = new License(5, 1000, constants.PM_SHOPPING_VIEW_PROTECTED_LICENSE, 0);
    private License license23 = new License(6, 5000, constants.PM_SHOPPING_VIEW_PROTECTED_LICENSE, 0);

    private License[] l11 = {license11};
    private License[] l12 = {license12};
    private License[] l13 = {license13};
    
    private License[] l21 = {license21};
    private License[] l22 = {license22};
    private License[] l23 = {license23};
    
    private LicensePackage currentLicensePackageList[] = {
        new LicensePackage(new Long(1), "Public View License 100","License for login in a created plattform 100 times.", getPrice(100,0.01,1.5) , l11 ),
        new LicensePackage(new Long(2), "Public View License 1000","License for login in a created plattform 1000 times.", getPrice(1000,0.01,1) , l12),
        new LicensePackage(new Long(3), "Public View License 5000","License for login in a created plattform 5000 times.", getPrice(5000,0.01,0.5), l13),
        new LicensePackage(new Long(4), "Protected View License 100","License for login in a created plattform 5000 times.", getPrice(100,0.02,1.5), l21),
        new LicensePackage(new Long(5), "Protected View License 1000","License for login in a created plattform 5000 times.", getPrice(1000,0.02,1), l22),
        new LicensePackage(new Long(6), "Protected View License 5000","License for login in a created plattform 5000 times.", getPrice(5000,0.02,0.5), l23)
    };

    private static final LicensePackage oldLicensePackageList[] = {};

    public List<LicensePackage> getCurrentLicensePackageList() {
        ArrayList<LicensePackage> list = new ArrayList<LicensePackage>();
        for(int i=0;i<currentLicensePackageList.length;i++) {
            list.add(currentLicensePackageList[i]);
        }
        return list;
    }

    public List<LicensePackage> getOldLicensePackageList() {
        ArrayList<LicensePackage> list = new ArrayList<LicensePackage>();
        for(int i=0;i<oldLicensePackageList.length;i++) {
            list.add(oldLicensePackageList[i]);
        }
        return list;
    }

    public List<LicensePackage> getAllLicensePackageList() {
        ArrayList<LicensePackage> list = new ArrayList<LicensePackage>();
        list.addAll(getCurrentLicensePackageList());
        list.addAll(getOldLicensePackageList());
        return list;
    }

    public LicensePackage getLicensePackageWithID(int id) {
        for(int i=0;i<currentLicensePackageList.length;i++) {
            if(currentLicensePackageList[i].getId()==id) {
                return currentLicensePackageList[i];
            }
        }
        for(int i=0;i<oldLicensePackageList.length;i++) {
            if(oldLicensePackageList[i].getId()==id) {
                return oldLicensePackageList[i];
            }
        }
        return null;
    }
}
